﻿<Window x:Class="LaunchMeNot.WinMain"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:LaunchMeNot"
    xmlns:l49ui="clr-namespace:Lime49.UI;assembly=Lime49"
    xmlns:l49wpf="clr-namespace:Lime49.WPF;assembly=Lime49" 
    xmlns:lex="http://schemas.root-project.org/xaml/presentation"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" 
    xmlns:conv="clr-namespace:LaunchMeNot.Converters" 
    x:Name="root" Title="LaunchMeNot" Height="600" Width="780"
    Topmost="{Binding ElementName=itmTopMost,Path=IsChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
    Style="{StaticResource {x:Type Window}}" Loaded="Window_Loaded"
    AllowDrop="True" DragEnter="Window_DragEnter" Drop="Window_Drop"
    Icon="pack://application:,,,/Resources/icon.ico">
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Close" Executed="CloseWindow" CanExecute="CanAlwaysExecute"/>
        <CommandBinding Command="ApplicationCommands.Delete" Executed="DeleteEntry" CanExecute="IsItemSelected"/>
        <CommandBinding Command="ApplicationCommands.Find" Executed="SearchOnline" CanExecute="IsParameterNull"/>
        <CommandBinding Command="ApplicationCommands.Help" Executed="ShowHelp" CanExecute="CanAlwaysExecute"/>
        <CommandBinding Command="ApplicationCommands.New" Executed="AddEntry" CanExecute="CanAlwaysExecute"/>
        <CommandBinding Command="ApplicationCommands.Open" Executed="OpenFileLocation" CanExecute="IsItemSelected"/>
        <CommandBinding Command="ApplicationCommands.Properties" Executed="EditEntry" CanExecute="IsItemSelected"/>
        <CommandBinding Command="NavigationCommands.GoToPage" Executed="OpenFileLocation" CanExecute="IsItemSelected"/>
        <CommandBinding Command="NavigationCommands.IncreaseZoom" Executed="MoveUp" CanExecute="CanMoveUp"/>
        <CommandBinding Command="NavigationCommands.DecreaseZoom" Executed="MoveDown" CanExecute="CanMoveDown"/>
        <CommandBinding Command="NavigationCommands.NextPage" Executed="CreateCopy" CanExecute="IsWorkerBusy"/>
        <CommandBinding Command="NavigationCommands.Refresh" Executed="RefreshEntries" CanExecute="IsWorkerBusy"/>
        <CommandBinding Command="loc:LaunchMeNotCommands.About" Executed="ShowAbout" CanExecute="CanAlwaysExecute"/>
        <CommandBinding Command="loc:LaunchMeNotCommands.Convert" Executed="ConvertEntry" CanExecute="IsItemSelected"/>
        <CommandBinding Command="loc:LaunchMeNotCommands.ExplorerProperties" Executed="OpenExplorerProperties" CanExecute="IsItemSelected"/>
        <CommandBinding Command="loc:LaunchMeNotCommands.Options" Executed="ShowOptions" CanExecute="CanAlwaysExecute"/>
        <CommandBinding Command="loc:LaunchMeNotCommands.ToggleInstall" Executed="ToggleInstall" CanExecute="CanAlwaysExecute"/>
        <CommandBinding Command="loc:LaunchMeNotCommands.Launch" Executed="AutoLaunch" CanExecute="CanAlwaysExecute"/>
        <CommandBinding Command="loc:LaunchMeNotCommands.Update" Executed="CheckForUpdate" CanExecute="CanAlwaysExecute"/>
    </Window.CommandBindings>
    <Window.Resources>
        <Image x:Key="copy_16" x:Shared="False" Source="pack://application:,,,/Resources/images/copy_16.png"/>
        <Image x:Key="convert_16" x:Shared="False" Source="pack://application:,,,/Resources/images/convert_16.png"/>
        <Image x:Key="delete_16" x:Shared="False" Source="pack://application:,,,/Resources/images/delete_16.png"/>
        <Image x:Key="directory_16" x:Shared="False" Source="pack://application:,,,/Resources/images/directory_16.png"/>
        <Image x:Key="down_16" x:Shared="False" Source="pack://application:,,,/Resources/images/down_16.png"/>
        <Image x:Key="edit_16" x:Shared="False" Source="pack://application:,,,/Resources/images/edit_16.png"/>
        <Image x:Key="gear_16" x:Shared="False" Source="pack://application:,,,/Resources/images/gear_16.png"/>
        <Image x:Key="help_16" x:Shared="False" Source="pack://application:,,,/Resources/images/question_16.png"/>
        <BitmapImage x:Key="launch_src_16" UriSource="pack://application:,,,/Resources/images/icon_16.png"/>
        <Image x:Key="launch_16" x:Shared="False" Source="{StaticResource launch_src_16}"/>
        <Image x:Key="new_16" x:Shared="False" Source="pack://application:,,,/Resources/images/new_16.png"/>
        <Image x:Key="registry_16" x:Shared="False" Source="pack://application:,,,/Resources/images/registry_16.png"/>
        <Image x:Key="startup_16" x:Shared="False" Source="pack://application:,,,/Resources/images/startup_16.png"/>
        <Image x:Key="search_16" x:Shared="False" Source="pack://application:,,,/Resources/images/search_16.png"/>
        <Image x:Key="up_16" x:Shared="False" Source="pack://application:,,,/Resources/images/up_16.png"/>
        <BitmapImage x:Key="windows_16" UriSource="pack://application:,,,/Resources/images/windows_16.png"/>
        
        <conv:EntryConversionConverter x:Key="EntryConversionConverter"/>
        <conv:EntryEqualityVisibilityConverter x:Key="EntryEqualityVisibilityConverter"/>
        <conv:ItemCountFormatter x:Key="ItemCountFormatter"/>
        <conv:SearchOnlineConverter x:Key="SearchOnlineConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.Resources>
            <Style TargetType="{x:Type dg:DataGridCell}" BasedOn="{StaticResource {x:Type dg:DataGridCell}}">
                <EventSetter Event="MouseDoubleClick" Handler="dgCell_MouseDoubleClick"/>
                <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown"/>
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="Transparent" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>

        <Menu Grid.Row="0" HorizontalContentAlignment="Left" HorizontalAlignment="Stretch">
            <MenuItem Header="File">
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:NewEntry}" Command="ApplicationCommands.New" Icon="{StaticResource new_16}" ToolTip="{lex:LocText LaunchMeNot.Core:Strings:AddAnApplicationToStartup}" />
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:Exit}" Command="ApplicationCommands.Close" />
            </MenuItem>
            <MenuItem Header="Tools">
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:AutoLaunch}" Command="loc:LaunchMeNotCommands.Launch" Icon="{StaticResource launch_16}" />
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:EnableAutoLaunch}">
                    <RadioButton Command="loc:LaunchMeNotCommands.ToggleInstall" CommandParameter="CurrentUserRun" Content="{lex:LocText LaunchMeNot.Core:Strings:CurrentUser}" x:Name="itmInstallCurrentUserStartup" />
                    <RadioButton Command="loc:LaunchMeNotCommands.ToggleInstall" CommandParameter="LocalMachineRun" Content="{lex:LocText LaunchMeNot.Core:Strings:AllUsers}" x:Name="itmInstallAllUsersStartup" />
                    <RadioButton Command="loc:LaunchMeNotCommands.ToggleInstall" CommandParameter="None" Content="{lex:LocText LaunchMeNot.Core:Strings:Disable}" x:Name="itmDisableInstall"/>
                </MenuItem>
                <Separator/>
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:AlwaysOnTop}" x:Name="itmTopMost" IsCheckable="True" Checked="SaveSettings" Unchecked="SaveSettings" />
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:Options}" Command="loc:LaunchMeNotCommands.Options" Icon="{StaticResource gear_16}" />
            </MenuItem>
            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:Help}">
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:HelpContents}" Command="ApplicationCommands.Help" Icon="{StaticResource help_16}" />
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:CheckForUpdate}" Command="loc:LaunchMeNotCommands.Update" />
                <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:About}" Command="loc:LaunchMeNotCommands.About" />
            </MenuItem>
        </Menu>
        
        <ToolBar Grid.Row="1" Grid.Column="0">
            <l49ui:ImageButton x:Name="btnNew" Command="ApplicationCommands.New" Style="{StaticResource ToolBarButton}" Image="pack://application:,,,/Resources/images/add_24.png" Text="{lex:LocText LaunchMeNot.Core:Strings:Add}" ToolTip="{lex:LocText LaunchMeNot.Core:Strings:AddAnApplicationToStartup}" />
            <l49ui:ImageButton x:Name="btnEdit" Command="ApplicationCommands.Properties" Style="{StaticResource ToolBarButton}" Image="pack://application:,,,/Resources/images/edit_24.png" Text="{lex:LocText LaunchMeNot.Core:Strings:Edit}" ToolTip="{lex:LocText LaunchMeNot.Core:Strings:EditItem}" />
            <l49ui:ImageButton x:Name="btnDelete" Command="ApplicationCommands.Delete" Style="{StaticResource ToolBarButton}" Image="pack://application:,,,/Resources/images/delete_24.png" Text="{lex:LocText LaunchMeNot.Core:Strings:Remove}" ToolTip="{lex:LocText LaunchMeNot.Core:Strings:RemoveApplicationFromStartup}" />
            <Separator/>
            <l49ui:ImageButton x:Name="btnRefresh" Command="NavigationCommands.Refresh" CommandParameter="{Binding SelectedItem,ElementName=lstLaunchMeNot}" CommandTarget="{Binding ElementName=lstLaunchMeNot}" 
                               Style="{StaticResource ToolBarButton}" Image="pack://application:,,,/Resources/images/refresh_24.png" Text="Refresh" ToolTip="{lex:LocText LaunchMeNot.Core:Strings:RefreshStartupEntries}" />
        </ToolBar>
       
        <TabControl Grid.Row="2" Grid.Column="0" x:Name="tbcLocations" Margin="6">
            <TabItem x:Name="tabLaunchMeNot">
                <TabItem.Header>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <Image Source="{StaticResource launch_src_16}" Width="16" Height="16" Margin="0,0,5,0" />
                        <TextBlock Text="LaunchMeNot"/>
                    </StackPanel>
                </TabItem.Header>
                <dg:DataGrid x:Name="lstLaunchMeNot" ItemsSource="{Binding LaunchMeNotEntries,ElementName=root,Mode=TwoWay}" IsSynchronizedWithCurrentItem="True" AutoGenerateColumns="False" 
                     CanUserAddRows="False" CanUserDeleteRows="False" PreviewKeyDown="lstLaunchMeNot_PreviewKeyDown" CellEditEnding="dg_CellEditEnding" VerticalAlignment="Stretch" SelectionMode="Extended" SelectionUnit="FullRow" CanUserSortColumns="True" 
                     HeadersVisibility="Column" EnableRowVirtualization="True" GridLinesVisibility="Horizontal" AlternationCount="2">
                    <dg:DataGrid.Columns>
                        <loc:AutoCommitCheckBoxColumn Binding="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsThreeState="False" IsReadOnly="False" CanUserResize="False"/>
                        <dg:DataGridTextColumn Binding="{Binding Name, Mode=OneWay}" Header="{lex:LocText LaunchMeNot.Core:Strings:Name}" IsReadOnly="True" Width="2*"/>
                        <dg:DataGridTextColumn Binding="{Binding FullPath, Mode=OneWay}" Header="{lex:LocText LaunchMeNot.Core:Strings:Path}" IsReadOnly="True" Width="3*"/>
                        <dg:DataGridTextColumn Binding="{Binding LaunchOrder, Mode=OneWay}" Header="{lex:LocText LaunchMeNot.Core:Strings:LaunchOrder}" IsReadOnly="True" Width="80"/>
                        <dg:DataGridTextColumn Binding="{Binding LaunchDelay, Mode=OneWay, StringFormat=0.#}" Header="{lex:LocText LaunchMeNot.Core:Strings:Delay}" IsReadOnly="True" Width="40"/>
                    </dg:DataGrid.Columns>
                    <dg:DataGrid.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:MoveUp}" Command="NavigationCommands.IncreaseZoom" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu}}" Icon="{StaticResource up_16}" />
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:MoveDown}" Command="NavigationCommands.DecreaseZoom" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu}}" Icon="{StaticResource down_16}" />
                            <Separator/>
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:ConvertTo}" Icon="{StaticResource convert_16}">
                                <MenuItem Header="LaunchMeNot" Command="loc:LaunchMeNotCommands.Convert" 
                                      CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryConversionConverter},ConverterParameter=LaunchMeNot}" Icon="{StaticResource launch_16}" 
                                      Visibility="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryEqualityVisibilityConverter},ConverterParameter=LaunchMeNot}">
                                    </MenuItem>
                                    <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:AllUsersStartupFolder}" Command="loc:LaunchMeNotCommands.Convert" 
                                      CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryConversionConverter},ConverterParameter=AllUsersStartup}" Icon="{StaticResource startup_16}" 
                                      Visibility="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryEqualityVisibilityConverter},ConverterParameter=AllUsersStartup}">
                                    </MenuItem>
                                    <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:CurrentUserStartupFolder}" Command="loc:LaunchMeNotCommands.Convert" 
                                      CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryConversionConverter},ConverterParameter=CurrentUserStartup}" Icon="{StaticResource startup_16}" 
                                      Visibility="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryEqualityVisibilityConverter},ConverterParameter=CurrentUserStartup}">
                                    </MenuItem>
                                    <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:RegistryCurrentUserRun}" Command="loc:LaunchMeNotCommands.Convert" 
                                      CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryConversionConverter},ConverterParameter=CurrentUserRun}" Icon="{StaticResource registry_16}" 
                                      Visibility="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryEqualityVisibilityConverter},ConverterParameter=CurrentUserRun}">
                                    </MenuItem>
                                    <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:RegistryLocalMachineRun}" Command="loc:LaunchMeNotCommands.Convert" 
                                      CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryConversionConverter},ConverterParameter=LocalMachineRun}" Icon="{StaticResource registry_16}" 
                                      Visibility="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource EntryEqualityVisibilityConverter},ConverterParameter=LocalMachineRun}">
                                    </MenuItem>
                            </MenuItem>
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:CreateCopy}" Command="NavigationCommands.NextPage" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu}}" Icon="{StaticResource copy_16}" />
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:Edit}" Command="ApplicationCommands.Properties" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu}}" Icon="{StaticResource edit_16}" />
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:Remove}" Command="ApplicationCommands.Delete" CommandTarget="{Binding PlacementTarget,RelativeSource={RelativeSource AncestorType=ContextMenu}}" Icon="{StaticResource delete_16}" />
                            <Separator/>
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:SearchOnline}" Icon="{StaticResource search_16}">
                                <MenuItem Header="Google" Command="ApplicationCommands.Find" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource SearchOnlineConverter},ConverterParameter='http://www.google.co.uk/search?q=%1'}"/>
                                <MenuItem Header="Bing" Command="ApplicationCommands.Find" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource SearchOnlineConverter},ConverterParameter='http://www.bing.com/search?q=%1'}" />
                                <MenuItem Header="ProcessLibrary.com" Command="ApplicationCommands.Find" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu},Converter={StaticResource SearchOnlineConverter},ConverterParameter='http://www.processlibrary.com/search/?q=%1'}" />
                            </MenuItem>
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:ExplorerProperties}" Command="loc:LaunchMeNotCommands.ExplorerProperties" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
                            <MenuItem Header="{lex:LocText LaunchMeNot.Core:Strings:OpenFileLocation}" Command="ApplicationCommands.Open" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType=ContextMenu}}" Icon="{StaticResource directory_16}" />
                        </ContextMenu>
                    </dg:DataGrid.ContextMenu>
                </dg:DataGrid>
            </TabItem>
            <TabItem x:Name="tabWindowsEntries">
                <TabItem.Header>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <Image Source="{StaticResource windows_16}" Width="16" Height="16" Margin="0,0,5,0"/>
                        <TextBlock Text="{lex:LocText LaunchMeNot.Core:Strings:WindowsStartup}"/>
                    </StackPanel>
                </TabItem.Header>
                <loc:StartupEntryDataGrid x:Name="windowsEntryGrid"/>
            </TabItem>
        </TabControl>

        <StatusBar Grid.Row="3" Grid.Column="0" MinHeight="24">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem Grid.Column="0">
                <TextBlock x:Name="lblRecordCount" Text="{Binding SelectedContent.Items.Count,ElementName=tbcLocations,Converter={StaticResource ItemCountFormatter}}" DockPanel.Dock="Left" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" Margin="2" />
            </StatusBarItem>
            <StatusBarItem Grid.Column="1">
                <Separator/>
            </StatusBarItem>
            <StatusBarItem Grid.Column="2">
                <TextBlock x:Name="lblStatus" DockPanel.Dock="Left" Visibility="Hidden" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" Margin="2" />
            </StatusBarItem>
            <StatusBarItem Grid.Column="3">
                <Separator/>
            </StatusBarItem>
            <StatusBarItem Grid.Column="4">
                <ProgressBar x:Name="prgStatus" DockPanel.Dock="Right" IsIndeterminate="True" MinWidth="40" Visibility="Hidden" />
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>
